<template>
  <div style="height: 100%; overflow:hidden" class="main">
    <!-- <x-header :left-options="{preventGoBack:true,backText: ''}" @on-click-back="backhome">隐患上报<div id="headeright"  @click="dangereport">上报</div></x-header> -->
    <div>
      <x-header :left-options="{preventGoBack:true,backText: ''}" @on-click-back="backhome">
        安全检查-离线
        <!-- <x-icon id="headeright" type="ios-plus-empty" size="30" @click="dangereport"></x-icon> -->
        <!-- <img slot="right" src="@/assets/img/offline_start.png" @click="dangereport" id="headeright" v-if="this.dangerArr.includes('0')"/> -->
        <img
          slot="right"
          src="@/assets/img/white_change.png"
          class="changeToOnline"
          @click="changeToOnline"
        />
      </x-header>
    </div>
    <!-- <img src="@/assets/img/add_form.png" class="add_form" @click="dangereport"
    v-if="this.dangerArr.includes('0')"/>-->
    <div class="add_form_new" @click="dangereport" v-if="this.dangerArr.includes('0')">发起</div>
    <div class="sup"  v-if="flagC"></div>
    <cell is-link link="proList">
      <span slot="title" style="font-weight:bold">{{showPro(pro)}}</span>
    </cell>
    <div class="sup"  v-if="flagC"></div>
    <!-- <group>
      <tab bar-position="bottom">
        <tab-item :selected="flagC" @on-item-click="onCheckClick">检查单</tab-item>
        <tab-item @on-item-click="onRectifyClick" :selected="flagR">整改单</tab-item>
      </tab>
      <cell is-link link="proList" v-if="flagC">
        <span slot="title" style="font-weight:bold">{{showPro(pro)}}</span>
      </cell>
      <cell is-link link="proListR" v-if="flagR">
        <span slot="title" style="font-weight:bold">{{showPro(pro)}}</span>
      </cell>
    </group>-->

    <div class="main-container" style="overflow:auto;height:70%;">
      <v-touch v-on:swiperight="onSwipeRight" :swipe-options="{direction: 'horizontal'}">
        <!-- <scroller :on-refresh="refresh" :on-infinite="infinite" ref="taskScroller"> -->
        <!-- <scroller  :on-infinite="infinite" ref="taskScroller"> -->
        <!-- content -->
        <!-- <scroller> -->
          <!-- <div v-bind:class="{check:this.flagC,rectify:this.flagR}"> -->
          <div style="display: flex;align-items: center;height: 30px;margin-top: 10px;">
            <input
              type="checkbox"
              name="selectAll"
              class="selectHidanger"
              id="selectAll"
              @click="selectAll"
              v-model="checked"
            />
            <label for="selectAll"></label>
            <div>全选</div>
          </div>
          <div v-if="flagC">
            <group v-for="(item, i) in list" gutter="-1px" :key="i">
              <div title :border-intent="false" style="display:flex">
                <input
                  type="checkbox"
                  name="selectHidanger"
                  class="selectHidanger"
                  :id="item.GUID"
                  v-model="checkList"
                  :value="item.GUID"
                />
                <label :for="item.GUID" style="width:30px"></label>
                <div class="more-box" style="margin:15px 0;width:100%" @click="openInfo(item)">
                  <!-- <div class="box-bar">
              <div style="font-size:16px">{{item.HAZARDCLAUSE}}</div>  
                  </div>-->
                  <div class="project_style">
                    <!-- <span class="gray-label" style="margin-right: 10px;"></span> -->
                    <!-- <span style="margin-right: 26px;margin-left: 46px;display:inline-block">{{item.INPUTERFULLNAME}}填写的安全检查表单</span> -->
                    <span style="display:inline-block">{{item.CONSTRUCTPRO}}</span>
                    <!-- <span class="gray-label" style="margin-right: 10px;">填写人</span>
                    <span class="hidanger-chosetaskfontshow">{{item.INPUTERFULLNAME}}</span>-->
                  </div>
                  <!-- <div style="margin-top: 8px;">
              <span class="gray-label" style="margin-right: 10px;">当前环节</span>
              {{item.CONSTURCTPRO}}
                  </div>-->
                  <div class="state_time_style">
                  <div class="fill_user">
                    <span class="gray-label" style="margin-right: 10px;">填写人</span>
                    {{item.INPUTERFULLNAME}}
                  </div>
                  <div class="fill_time">
                    <span class="gray-label" style="margin-right: 10px;">填写时间</span>
                    {{item.INPUTDATE.substring(0,10)}}
                  </div>
                  </div>
                </div>
              </div>
            </group>
          </div>

          <div v-if="flagR">
            <group v-for="(item, i) in listR" gutter="-1px" :key="i">
              <div title :border-intent="false" @click="openInfoR(item)">
                <div
                  class="more-box"
                  style="margin-left: 30px;margin-right: 30px;margin-bottom: 15px;margin-top: 15px;"
                >
                  <!-- <div class="box-bar">
              <div style="font-size:16px">{{item.HAZARDCLAUSE}}</div>
                  </div>-->
                  <div style="margin-top: 8px;">
                    <!-- <span class="gray-label" style="margin-right: 10px;"></span> -->
                    <!-- <span style="margin-right: 26px;margin-left: 46px;display:inline-block">{{item.INPUTERFULLNAME}}填写的安全检查表单</span> -->
                    <span style="display:inline-block">{{item.PRJNAME}}</span>
                    <!-- <span class="gray-label" style="margin-right: 10px;">填写人</span>
                    <span class="hidanger-chosetaskfontshow">{{item.INPUTERFULLNAME}}</span>-->
                  </div>
                  <!-- <div style="margin-top: 8px;">
              <span class="gray-label" style="margin-right: 10px;">当前环节</span>
              {{item.CONSTURCTPRO}}
                  </div>-->
                  <div style="margin-top: 8px; display: inline-flex;">
                    <span class="gray-label" style="margin-right: 10px;">填写人</span>
                    {{item.INPUTERFULLNAME}}
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <img
                      src="@/assets/img/待整改@2x.png"
                      width="20%"
                      height="10%"
                      v-if="item.STATE=='未确认'"
                    />
                    <img
                      src="@/assets/img/整改中@2x.png"
                      width="20%"
                      height="10%"
                      v-if="item.STATE=='整改中'"
                    />
                    <img
                      src="@/assets/img/暂存@2x.png"
                      width="20%"
                      height="10%"
                      v-if="item.STATE=='暂存'"
                    />
                    <img
                      src="@/assets/img/已整改@2x.png"
                      width="20%"
                      height="10%"
                      v-if="item.STATE=='已完成'"
                    />
                  </div>
                  <div style="margin-top: 8px;  ">
                    <span class="gray-label" style="margin-right: 10px;">填写时间</span>
                    {{item.INPUTDATE.substring(0,10)}}
                  </div>
                </div>
              </div>
            </group>
          </div>
        <!-- </scroller> -->
      </v-touch>
    </div>
    <!-- <img :src="uploadImgUrl" class="upload" @click="uploadRecodes" v-show="uploadFlag" /> -->
    <div class="upload_div" v-show="uploadFlag"><div class="add_form" @click="uploadRecodes">上传</div></div>
    <router-view></router-view>
  </div>
</template>

<script>
import { Checklist } from "vux";
var $vue = {};
export default {
  name: "offlinehidangerlist",
  // inject:['reload'],
  components: {
    Checklist
  },
  beforeCreate() {
    $vue = this;
  },
  mounted() {
    // this.checkSelectR();
    // this.getData();
    this.getDataOffline();

    // var test=this.guid();
    this.pageToken = this.guid();
  },
  data() {
    return {
      list: [],
      listR: [],
      page: 1,
      keyword: "",
      createPop: false, //弹出层是否创建
      loading: false, //下拉刷新时禁止无限加载
      //currentTab:'待整改',
      //tabs:['待整改','已整改']
      pro: this.$route.query.pro,
      proId: this.$route.query.proId,
      proDept: this.$route.query.proDept,
      site: this.$route.query.site,
      // guid: "",
      flagC: true,
      flagR: false,
      checkSelect: "",
      //proName:'',
      checked: false, //全选框
      checkList: [],
      uploadImgUrl: require("@/assets/img/upload.png"),
      selectedList: [], //已选中的list
      pageToken: "",
      fieldToken: "",
      imgList: this.$store.state.offlineflieurl, //本地图片存储路径
      offlineUrl: [], //要上传至服务器的url
      uploadFlag: false,
      dangerArr: this.$store.state.dangerArr,
      successFlag: 0,
      successFlagUpdate: []
    };
  },
  methods: {
    //上传文件
    upload(fileURL, guid, data, length, index) {
      console.log("upload:" + fileURL, guid);
      var success = r => {
        //上传成功
        console.log("传上成功");
        console.log("rrrrrrr", r);

        this.imgList.map(item => {
          if (true) {
            // if (this.belongSubSys != '') {
            item.fileOldName = JSON.parse(r.response)[0].name;
            item.fileId = JSON.parse(r.response)[0].id;
            item.fieldToken = JSON.parse(r.response)[0].fieldToken;
            item.size = JSON.parse(r.response)[0].size;
            // } else if (this.server != '') {
            // item.fileId = JSON.parse(r.response).fileId // moaapi/feedback 接口
            // }
          }
        });
        if (!this.successFlagUpdate[index]) {
          this.successFlagUpdate[index] = 0;
        }
        this.successFlagUpdate[index]++;
        // this.$set(this.successFlagUpdate,this.successFlag,1);
        // this.successFlagUpdate[i] = this.successFlag

        if (this.successFlagUpdate[index] == length) {
          this.successFlagUpdate[index] = 0;
          delete this.list[index];
          var params = {
            _method: "formService.saveFormData",
            requestEventData: {
              eventType: "formSubmitEvent",
              formType: 1,
              bizObjId: "PMHSE_INSPECTION",
              formId: "PMHSE_INSPECTION_ADD",
              buttonId: this.guid()
            },
            _OBJ_NAME_: "PMHSE_INSPECTION",
            _FORM_ID_: "PMHSE_INSPECTION_ADD",
            useType: "add",
            pageToken: this.pageToken,
            formData: {
              objName: "PMHSE_INSPECTION",
              pks: ["GUID"],
              data: [
                {
                  rowData: [
                    {
                      DataTarget: "GUID",
                      Value: "",
                      OriginalValue: null,
                      PK: true,
                      DataType: "String"
                    },
                    {
                      DataTarget: "RESTATE",
                      Value: "0",
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "PRODEPT",
                      Value: data.PRODEPT,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CONSTRUCTPRO",
                      Value: data.CONSTRUCTPRO,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "PROJECTID",
                      Value: data.PROJECTID,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "SYSPRJID",
                      Value: data.SYSPRJID,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CENTERPOSITION",
                      Value: data.CENTERPOSITION,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKDATE",
                      Value: data.CHECKDATE,
                      OriginalValue: null,
                      PK: false,
                      DataType: "DATE"
                    },
                    {
                      DataTarget: "CHECKMONTH",
                      Value: data.CHECKMONTH,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKYEAR",
                      Value: data.CHECKYEAR,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKMY",
                      Value: data.CHECKMY,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "FATHERCLASS_TEXT",
                      Value: data.FATHERCLASS_TEXT,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "FATHERCLASS",
                      Value: data.FATHERCLASS,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKPRO_TEXT",
                      Value: data.CHECKPRO_TEXT,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKPRO",
                      Value: data.CHECKPRO,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKQUARTER",
                      Value: data.CHECKQUARTER,
                      OriginalValue: null,
                      PK: false,
                      DataType: "int"
                    },
                    {
                      DataTarget: "CHECKITEMS_TEXT",
                      Value: data.CHECKITEMS_TEXT,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKITEMS",
                      Value: data.CHECKITEMS,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "SECURITYLEVEL",
                      Value: "一般",
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHILDCLASS",
                      Value: data.CHILDCLASS,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "IMPORTANCE",
                      Value: data.IMPORTANCE,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "WEIGHT",
                      Value: data.WEIGHT,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "SYSTODAY",
                      Value: data.SYSTODAY,
                      OriginalValue: null,
                      PK: false,
                      DataType: "TimeStamp"
                    },
                    {
                      DataTarget: "DESCRIPTION",
                      Value: data.DESCRIPTION,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "HIDDENNUM",
                      Value: 0,
                      OriginalValue: null,
                      PK: false,
                      DataType: "int"
                    },
                    {
                      DataTarget: "PROSCORE",
                      Value: 0,
                      OriginalValue: null,
                      PK: false,
                      DataType: "int"
                    },
                    {
                      DataTarget: "ACTSCORE",
                      Value: 0,
                      OriginalValue: null,
                      PK: false,
                      DataType: "int"
                    },
                    {
                      DataTarget: "ATTACHMENTS",
                      Value: data.ATTACHMENTS,
                      OriginalValue: null,
                      PK: false,
                      DataType: "Store.ecidiDoc"
                    },
                    {
                      DataTarget: "INPUTERFULLNAME",
                      Value: data.INPUTERFULLNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "INPUTERNAME",
                      Value: data.INPUTERNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "PHONENUM",
                      Value: data.PHONENUM,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "INPUTERDEPTNAME",
                      Value: data.INPUTERDEPTNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "INPUTDATE",
                      Value: data.INPUTDATE,
                      OriginalValue: null,
                      PK: false,
                      DataType: "TimeStamp"
                    },
                    {
                      DataTarget: "ISREPLY",
                      Value: data.ISREPLY,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    }
                  ],
                  children: []
                }
              ]
            },
            _ATTACHMENT_DELETE_IDS_: "",
            formInfo: {
              GUID: "",
              RESTATE: "1",
              CONSTRUCTPRO: data.CONSTRUCTPRO,
              PRODEPT: data.PRODEPT,
              SYSPRJID: data.SYSPRJID,
              CENTERPOSITION: data.CENTERPOSITION,
              CHECKDATE: data.CHECKDATE,
              CHECKMONTH: data.CHECKMONTH,
              CHECKYEAR: data.CHECKYEAR,
              CHECKMY: data.CHECKMY,
              FATHERCLASS_TEXT: data.FATHERCLASS_TEXT,
              FATHERCLASS: data.FATHERCLASS,
              CHECKPRO_TEXT: data.CHECKPRO_TEXT,
              CHECKPRO: data.CHECKPRO,
              CHECKQUARTER: data.CHECKQUARTER,
              CHECKITEMS_TEXT: data.CHECKITEMS_TEXT,
              CHECKITEMS: data.CHECKITEMS,
              SECURITYLEVEL: "一般",
              CHILDCLASS: data.CHILDCLASS,
              IMPORTANCE: data.IMPORTANCE,
              WEIGHT: data.WEIGHT,
              SYSTODAY: data.SYSTODAY,
              DESCRIPTION: data.DESCRIPTION,
              HIDDENNUM: "0",
              PROSCORE: "0",
              ACTSCORE: "0",
              ATTACHMENTS: this.fieldToken,
              INPUTERFULLNAME: data.INPUTERFULLNAME,
              INPUTERNAME: data.INPUTERNAME,
              PHONENUM: data.PHONENUM,
              INPUTERDEPTNAME: data.INPUTERDEPTNAME,
              INPUTDATE: data.INPUTDATE,
              ISREPLY:data.ISREPLY
            }
          };
          let json = {
            FixJSON: JSON.stringify(params)
          };
          console.log("开始保存表单");
          this.$ajax({
            url: this.COMMON_URL + "?_viewId=PMHSE_INSPECTION",
            method: "post",
            data: json,
            async: false
          })
            .then(res => {
              //上传图片变灰
              console.log("上传成功了吗？", res);
              this.uploadImgUrl = require("@/assets/img/upload.png");
              this.$store.state.SQLiteDB.transaction(
                tx => {
                  tx.executeSql(
                    'DELETE FROM PMHSE_INSPECTION WHERE GUID="' +
                      data.GUID +
                      '"'
                  );
                },
                err => {
                  console.log("错误", err);
                }
              );

              this.$store.state.SQLiteDB.transaction(tx => {
                tx.executeSql(
                  "SELECT * FROM PMHSE_INSPECTION",
                  [],
                  (tx, result) => {
                    if(result.rows.length == 0){
                      this.list = [];
                    }
                    for (let i = 0; i < result.rows.length; i++) {
                        this.list[i] = result.rows.item(i);
                    }
                  }
                );
              });
              // this.toastValue = true;
              //console.log("");
            })
            .catch(err => {
              console.log(err);
              alert(err);
              //this.err='';
            });
        }
        // this.showPercent = false
        // this.percent = 0
        //  this.$emit('input', this.list)
        // this.show = false
      };
      var fail = error => {
        // 上传失败
        console.log("上传失败")
        console.log(JSON.stringify(error));
        // //console.log('photoFailed')
        // this.showPercent = false
        // this.percent = 0
        // console.log("上传失败")
      };
      var options = new FileUploadOptions();
      console.log("fileUpload:" + options);
      options.fileKey = "fileName";
      options.fileName = fileURL.substr(
        fileURL.lastIndexOf("/"),
        fileURL.lastIndexOf("?") - fileURL.lastIndexOf("/")
      );
      if (!options.fileName) {
        options.fileName = fileURL.substr(fileURL.lastIndexOf("/"));
      }
      options.mimeType = "application/octet-stream";
      (options.httpMethod = "POST"),
        (options.headers = {
          Accept: "*/*",
          "Accept-Encoding:": "gzip, deflate",
          "Accept-Language": " zh-CN,zh;q=0.9",
          Connection: "keep-alive"
        });
      (options.chunkedMode = false),
        // 如果要传参数，写这里
        (options.params = {
          Filename: fileURL.substr(fileURL.lastIndexOf("/") + 1),
          Upload: "Submit Query"
          // modularName: 'CNL',
          // allowType: 'jpeg;jpg;png;pdf;doc;xls;xlsx;docx',
        });
      var ft = new FileTransfer();
      //注册监听上传进度
      ft.onprogress = progressEvent => {
        if (progressEvent) {
          this.percent = Math.round(
            (progressEvent.loaded * 100) / progressEvent.total
          );
        }
      };
      let params =
        "type=customerDownloadService&FixJSON={%27_method%27:%27streamSupportService.saveTempAttachment%27,%27_param%27:{pageToken:%27" +
        this.pageToken +
        "%27,fieldToken:%27" +
        this.fieldToken +
        "%27,datatype:%27Store.ecidiDoc%27}}";
      if (device.platform == "iOS") {
        // params =
        // "type=customerDownloadService&FixJSON={%27_method%27:%27streamSupportService.saveTempAttachment%27,%27_param%27:{pageToken:%27" +
        // this.pageToken + "%27,fieldToken:%27" + this.fieldToken + "%27,datatype:%27Store.ecidiDoc%27}}"
        params =
          "type=customerDownloadService&FixJSON={'_method':'streamSupportService.saveTempAttachment','_param':{'pageToken':'" +
          this.pageToken +
          "','fieldToken':'" +
          this.fieldToken +
          "',datatype:'Store.ecidiDoc'}}";
      }
      //'type=%27customerDownloadService%27&FixJSON=%7B%27_method%27:%27streamSupportService.saveTempAttachment%27,%27_param%27:%7B%27pageToken%27:%27' +
      //  this.pageToken + '%27,%27fieldToken%27:%27' + this.fieldToken + '%27%7D%7D'

      //上传地址
      let SERVER = "";
      // if (this.belongSubSys != '') {
      SERVER =
        this.COMMON_URL.replace("Action.cmd", "StreamSupportAction.cmd") +
        "?" +
        params;
      // }
      // console.log('开始上传'+SERVER)
      // if (this.server != '') {
      //   SERVER = this.server
      //   params = this.params == '' ? '' : this.params
      // }
      console.log("开始上传" + SERVER);
      if (device.platform == "iOS") {
        SERVER = encodeURI(SERVER);
      }
      console.log("optionoffline", options);
      console.log(fileURL);
      ft.upload(fileURL, SERVER, success, fail, options);
    },
    uploadRecodes() {
      this.uploadImgUrl = require("@/assets/img/upload_active.png");
      if (this.checkNetWork()) {
        for (let i = this.selectedList.length - 1; i >= 0; i--) {
          console.log(this.selectedList[i]);
          this.$store.state.SQLiteDB.transaction(tx => {
            tx.executeSql(
              'SELECT * FROM PMHSE_INSPECTION WHERE GUID = "' +
                this.selectedList[i] +
                '"',
              [],
              (tx, result) => {
                console.log("上传测试查询结果", result);
                if (result.rows) {
                  $vue.uploadToServer(result.rows.item(0), i);
                } else {
                  // alert("请选择需要上传的检查单");
                  this.$vux.alert.show({
                    title:"提示",
                    content:"请选择需要上传的检查单！"
                  })
                }
              }
            );
          });
        }
      } else {
        //执行离线状态时的任务
        console.log("离线工作！");
        // alert("请连接互联网进行上传操作！");
        this.$vux.alert.show({
          title:"提示",
          content:"请连接互联网进行上传操作！"
        })
      }
    },
    uploadToServer(data, index) {
      this.fieldToken = data.ATTACHMENTS;
      let res = data.FILEURL;
      res = res.replace(/\|\|/g, ".");
      this.offlineUrl = res.split(",");
      var length = this.offlineUrl.length;
      console.log("图片list", this.imgList);
      if(this.imgList.length == 0){
        var params = {
            _method: "formService.saveFormData",
            requestEventData: {
              eventType: "formSubmitEvent",
              formType: 1,
              bizObjId: "PMHSE_INSPECTION",
              formId: "PMHSE_INSPECTION_ADD",
              buttonId: this.guid()
            },
            _OBJ_NAME_: "PMHSE_INSPECTION",
            _FORM_ID_: "PMHSE_INSPECTION_ADD",
            useType: "add",
            pageToken: this.pageToken,
            formData: {
              objName: "PMHSE_INSPECTION",
              pks: ["GUID"],
              data: [
                {
                  rowData: [
                    {
                      DataTarget: "GUID",
                      Value: "",
                      OriginalValue: null,
                      PK: true,
                      DataType: "String"
                    },
                    {
                      DataTarget: "RESTATE",
                      Value: "0",
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "PRODEPT",
                      Value: data.PRODEPT,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CONSTRUCTPRO",
                      Value: data.CONSTRUCTPRO,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "PROJECTID",
                      Value: data.PROJECTID,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "SYSPRJID",
                      Value: data.SYSPRJID,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CENTERPOSITION",
                      Value: data.CENTERPOSITION,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKDATE",
                      Value: data.CHECKDATE,
                      OriginalValue: null,
                      PK: false,
                      DataType: "DATE"
                    },
                    {
                      DataTarget: "CHECKMONTH",
                      Value: data.CHECKMONTH,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKYEAR",
                      Value: data.CHECKYEAR,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKMY",
                      Value: data.CHECKMY,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "FATHERCLASS_TEXT",
                      Value: data.FATHERCLASS_TEXT,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "FATHERCLASS",
                      Value: data.FATHERCLASS,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKPRO_TEXT",
                      Value: data.CHECKPRO_TEXT,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKPRO",
                      Value: data.CHECKPRO,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKQUARTER",
                      Value: data.CHECKQUARTER,
                      OriginalValue: null,
                      PK: false,
                      DataType: "int"
                    },
                    {
                      DataTarget: "CHECKITEMS_TEXT",
                      Value: data.CHECKITEMS_TEXT,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKITEMS",
                      Value: data.CHECKITEMS,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "SECURITYLEVEL",
                      Value: "一般",
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHILDCLASS",
                      Value: data.CHILDCLASS,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "IMPORTANCE",
                      Value: data.IMPORTANCE,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "WEIGHT",
                      Value: data.WEIGHT,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "SYSTODAY",
                      Value: data.SYSTODAY,
                      OriginalValue: null,
                      PK: false,
                      DataType: "TimeStamp"
                    },
                    {
                      DataTarget: "DESCRIPTION",
                      Value: data.DESCRIPTION,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "HIDDENNUM",
                      Value: 0,
                      OriginalValue: null,
                      PK: false,
                      DataType: "int"
                    },
                    {
                      DataTarget: "PROSCORE",
                      Value: 0,
                      OriginalValue: null,
                      PK: false,
                      DataType: "int"
                    },
                    {
                      DataTarget: "ACTSCORE",
                      Value: 0,
                      OriginalValue: null,
                      PK: false,
                      DataType: "int"
                    },
                    {
                      DataTarget: "ATTACHMENTS",
                      Value: data.ATTACHMENTS,
                      OriginalValue: null,
                      PK: false,
                      DataType: "Store.ecidiDoc"
                    },
                    {
                      DataTarget: "INPUTERFULLNAME",
                      Value: data.INPUTERFULLNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "INPUTERNAME",
                      Value: data.INPUTERNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "PHONENUM",
                      Value: data.PHONENUM,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "INPUTERDEPTNAME",
                      Value: data.INPUTERDEPTNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "INPUTDATE",
                      Value: data.INPUTDATE,
                      OriginalValue: null,
                      PK: false,
                      DataType: "TimeStamp"
                    },
                    {
                      DataTarget: "ISREPLY",
                      Value: data.ISREPLY,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    }
                  ],
                  children: []
                }
              ]
            },
            _ATTACHMENT_DELETE_IDS_: "",
            formInfo: {
              GUID: "",
              RESTATE: "1",
              CONSTRUCTPRO: data.CONSTRUCTPRO,
              PRODEPT: data.PRODEPT,
              SYSPRJID: data.SYSPRJID,
              CENTERPOSITION: data.CENTERPOSITION,
              CHECKDATE: data.CHECKDATE,
              CHECKMONTH: data.CHECKMONTH,
              CHECKYEAR: data.CHECKYEAR,
              CHECKMY: data.CHECKMY,
              FATHERCLASS_TEXT: data.FATHERCLASS_TEXT,
              FATHERCLASS: data.FATHERCLASS,
              CHECKPRO_TEXT: data.CHECKPRO_TEXT,
              CHECKPRO: data.CHECKPRO,
              CHECKQUARTER: data.CHECKQUARTER,
              CHECKITEMS_TEXT: data.CHECKITEMS_TEXT,
              CHECKITEMS: data.CHECKITEMS,
              SECURITYLEVEL: "一般",
              CHILDCLASS: data.CHILDCLASS,
              IMPORTANCE: data.IMPORTANCE,
              WEIGHT: data.WEIGHT,
              SYSTODAY: data.SYSTODAY,
              DESCRIPTION: data.DESCRIPTION,
              HIDDENNUM: "0",
              PROSCORE: "0",
              ACTSCORE: "0",
              ATTACHMENTS: this.fieldToken,
              INPUTERFULLNAME: data.INPUTERFULLNAME,
              INPUTERNAME: data.INPUTERNAME,
              PHONENUM: data.PHONENUM,
              INPUTERDEPTNAME: data.INPUTERDEPTNAME,
              INPUTDATE: data.INPUTDATE,
              ISREPLY:data.ISREPLY
            }
          };
          let json = {
            FixJSON: JSON.stringify(params)
          };
          console.log("开始保存表单");
          this.$ajax({
            url: this.COMMON_URL + "?_viewId=PMHSE_INSPECTION",
            method: "post",
            data: json,
            async: false
          })
            .then(res => {
              //上传图片变灰
              console.log("上传成功了吗？", res);
              this.uploadImgUrl = require("@/assets/img/upload.png");
              this.$store.state.SQLiteDB.transaction(
                tx => {
                  tx.executeSql(
                    'DELETE FROM PMHSE_INSPECTION WHERE GUID="' +
                      data.GUID +
                      '"'
                  );
                },
                err => {
                  console.log("错误", err);
                }
              );

              this.$store.state.SQLiteDB.transaction(tx => {
                tx.executeSql(
                  "SELECT * FROM PMHSE_INSPECTION",
                  [],
                  (tx, result) => {
                    if ( result.rows.length == 0 ){
                      this.list = [];
                    }
                    for (let i = 0; i < result.rows.length; i++) {
                      this.list[i] = result.rows.item(i);
                    }
                  }
                );
              });
              // this.toastValue = true;
              //console.log("");
            })
            .catch(err => {
              console.log(err);
              alert(err);
              //this.err='';
            });
        
      }else{
        for (var j = 0; j < this.offlineUrl.length; j++) {
          (function(j) {
            $vue.upload($vue.offlineUrl[j], $vue.guid(), data, length, index);
            // $vue.upload($vue.offlineUrl[j], $vue.imgList[j].guid);
          })(j);
        }
      }
      
      //  while(this.successFlag == this.offlineUrl.length - 1){

      //   }
    },
    selectAll() {
      if (this.checked) {
        //实现反选
        this.checkList = [];
      } else {
        //实现全选
        this.checkList = [];
        for (var i = 0; i < this.list.length; i++) {
          this.checkList.push(this.list[i].GUID);
        }
      }
    },
    //切换至在线模式
    changeToOnline() {
      this.$router.push({
        name: "hidangerlist",
        path: "/hidangereport"
      });
    },
    checkSelectR() {
      if (this.$route.query.flag == 1) {
        this.flagC = false;
        this.flagR = true;
        console.log("换纸");
      } else {
        this.flagC = true;
        this.flagR = false;
        console.log("不换");
      }
    },
    onCheckClick() {
      this.flagC = true;
      this.flagR = false;
      //$(".check").show();
      //console.log(this.flag)
    },
    onRectifyClick() {
      this.flagC = false;
      this.flagR = true;
      //$(".check").hide();
      //console.log(this.flag)
    },
    onSwipeRight() {
      this.$router.push("/index/home");
    },
    backhome() {
      this.$router.push("/index/home");
    },
    getData(callback, failed) {
      var filter = "1=1";
      //console.log(this.proId);
      if (!this.proId) {
        filter = "ISDELETE IS NULL";
      } else {
        filter = "ISDELETE IS NULL AND SYSPRJID='" + this.proId + "'";
      }
      var params =
        '{"_method":"component.getListData","_param":{"bizObj":"PMHSE_INSPECTION","service":"selectMore","fields":"*","filter":' +
        '"' +
        filter +
        '"' +
        ',"currentPageIndex":1,"pageSize":50,"orderList":[{"field":"NUMZZ","order":"desc"}],"QueryFormData":""}}';
      this.$ajax({
        method: "post",
        url:
          this.COMMON_URL +
          "?_objName=PMHSE_INSPECTION&_viewId=PMHSE_INSPECTION",
        data: {
          FixJSON: params
        }
      })
        .then(res => {
          //console.log(res)
          // callback(res)
          //consoel.log("asasdasdasasd");
          this.list = [...res.data.datas];
          console.log(this.list);
          this.page++;
        })
        .catch(err => {
          failed();
        });
      // this.reload();
      //this.$router.go(0)
    },
    getDataOffline() {
      if (this.proId != undefined) {
        this.$store.state.SQLiteDB.transaction(tx => {
          tx.executeSql(
            "SELECT * FROM PMHSE_INSPECTION where PROJECTID ='" +
              this.proId +
              "'",
            [],
            (tx, result) => {
              console.log(result);
              for (let i = 0; i < result.rows.length; i++) {
                  this.list[i] = result.rows.item(i);
              }
              console.log(this.list);

              if (this.list.length > 0) {
                this.uploadFlag = true;
              }
            }
          );
        });
      } else {
        this.$store.state.SQLiteDB.transaction(tx => {
          tx.executeSql("SELECT * FROM PMHSE_INSPECTION", [], (tx, result) => {
            console.log(result);
            for (let i = 0; i < result.rows.length; i++) {
              this.list[i] = result.rows.item(i);
            }
            console.log(this.list);
            if (this.list.length > 0) {
              this.uploadFlag = true;
            }
          });
        });
      }
    },
    openInfo(item) {
      this.$router.push({
        path: "/hidangereport/offlineInspDetail",
        query: {
          GUID: item.GUID,
          pro: item.CONSTRUCTPRO,
          site: item.CENTERPOSITION,
          pmname: item.PRODEPT
        }
      });
    },

    infinite(done) {
      //上划加载方法
      // console.log("infinite");
      // console.log(this.page);

      this.getData(res => {
        //res.data.datas中的字段都是大写的，res.data.data中的字段有小写的

        this.list = [...this.list, ...res.data.datas]; //TODO 啥意思
        this.page++;
        done();
      });
    },
    refresh(done) {
      this.page = 1;
      // // console.log("refresh");
      // // console.log(this.page);
      // debugger
      // this.loading = true;
      this.getData(res => {
        this.list = [...res.data.datas];
        this.page++;
      });
    },
    search(val) {
      this.page = 1;
      this.keyword = val;
      this.getData(
        res => {
          if (res.status == "200" && res.data.datas.length > 0) {
            this.list = [...res.data.datas];
            this.page++;
          } else {
            this.list = [];
          }
        },
        () => {
          this.list = [];
        }
      );
    },
    dangereport() {
      console.log(this.$route.query);
      if (this.flagC)
        this.$router.push({
          path: "/hidangereport/InspectionInfo",
          query: this.$route.query
        });
      else
        this.$router.push({
          path: "/hidangereport/rectifyInfo",
          query: { pro: this.pro, proId: this.proId, pmname: this.proDept }
        });
    },
    changeType(val) {
      this.page = 1;
      this.currentTab = val;
      this.list = [];
      this.$refs.taskScroller.finishInfinite(false);
    },
    showPro(pro) {
      return !!pro ? pro : "全部项目";
    }
  },

  computed: {
    row() {
      return this.$store.state.currentRow;
    }
  },
  watch: {
    proId: function(newId, old, Id) {},
    checkList: {
      handler: function(val, oldVal) {
        this.selectedList = this.checkList;
        if (val.length === this.list.length) {
          this.checked = true;
        } else {
          this.checked = false;
        }
      },
      deep: true
    }
  }
};
</script>

<style scoped>
.transition-view /deep/ .vux-header .vux-header-left .left-arrow:before {
  border-color: #cccccc;
}
.transition-view /deep/ .vux-header {
  background-color: #262a34 !important;
}
.transition-view .vux-header /deep/ .vux-header-title {
  color: #ffffff;
}
.card {
  background: #fff;
  margin: 10px 16px;
  padding: 20px;
  border-radius: 4px;
  overflow: hidden;
}

.card-title {
  font-size: 18px;
}
.warning {
  color: red;
  padding: 0 5px;
  background-color: pink;
  text-align: center;
  width: 140px;
  line-height: 30px;
  font-size: 14px;
}

.gray-label {
  color: gray;
}

#headeright {
  position: absolute;
  right: 0px;
  top: 5px;
  display: block;
  font-size: 14px;
  line-height: 21px;
  width: 20px;
  height: 20px;
}
.box-bar:before {
  content: "";
  display: block;
  height: 17px;
  position: absolute;
  border-left: 4px solid #a7aeff;
  left: 14px;
  top: 18px;
}
.hidanger-chosetaskfontshow {
  max-width: 70px;
  overflow-x: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: inline-block;
  /*设置overflow后基线位置改变，因此需要调整*/
  vertical-align: bottom;
}
.changeToOnline {
  margin-right: auto;
  width: 25px;
  height: 25px;
}
.selectHidanger {
  display: none;
}
.selectHidanger + label {
  background-color: #eeeeee;
  border-radius: 4px;
  border: 1px solid #d3d3d3;
  width: 20px;
  height: 20px;
  display: inline-block;
  text-align: center;
  vertical-align: bottom;
  line-height: 20px;
  margin: 25px;
}
.selectHidanger + label:hover {
  cursor: pointer;
  border: 1px solid #262a34;
}
.selectHidanger:checked + label {
  background-color: #eeeeee;
  background: #262a34;
}
.selectHidanger:checked + label:after {
  content: "\2714";
  color: white;
}
.upload {
  z-index: 999;
  position: absolute;
  top: 75%;
  left: 80%;
  width: 50px;
  height: 50px;
}
.add_form {
  position: relative;
  height: 50px;
  width: 90%;
  top: 8px;
  z-index: 999;
  left: 5%;
  background: #262a34;
  color: #ffffff;
  font-size:16px;
  font-family:PingFang SC;
  font-weight:400;
  line-height:20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.add_form_new {
  position: absolute;
  width:50px;
  height:50px;
  top: 80%;
  z-index: 999;
  left: 80%;
  background:#262a34;
  box-shadow:0px 1px 13px 0px #262a34;
  border-radius:50%;
  color: #ffffff;
  font-size:14px;
  font-family:PingFang SC;
  font-weight:400;
  line-height:24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sup{
  width: 100%;
  height: 10px;
  border-radius: 0;
  background-color: #F5F5F5;
}
.project_style{
  font-size:15px;
font-family:PingFang SC;
font-weight:400;
color:rgba(25,25,25,1);
line-height:20px;
margin-top: 8px
}
.state_time_style{
  display: flex;
  margin-top: 8px;
}
.fill_user{
  font-size: 13px;
  font-family: PingFang SC;
  font-weight: 400;
  color: rgba(175,175,175,1);
  line-height: 20px;
}
.fill_time{
  margin-left: auto;
  font-size: 12px;
  font-family: PingFang SC;
  font-weight: 400;
  color: rgba(175,175,175,1);
  line-height: 20px;
  margin-right: auto;
}
/* .transition-view .vux-header .vux-header-left /deep/.left-arrow:before{
   border: 1px solid rgb(228, 15, 15);
 } */
 .upload_div{
   border-top: 1px solid rgb(238, 238, 238);
    /* position: relative;
    bottom: 60px; */
 }
</style>
